<template>
  <div>
    <zm-dialog
      title="批量设置"
      :visible.sync="value"
      append-to-body
      :before-close="dialogClose"
      :close-on-click-modal="false"
      :keep-alive="true"
    >
    <zm-form :model="form" :rules="rules" label-width="200px" label-position="right">
      <zm-form-item label="最低销售数量" prop="minSaleNumber">
          <zm-form-item prop="minSaleNumberOperationSymbol" class="dib">
            <el-select
              class="w100"
              v-model="form.minSaleNumberOperationSymbol"
              placeholder="请选择"
            >
              <el-option label="大于" value="1"></el-option>
              <el-option label="大于等于" value="2"></el-option>
            </el-select>
          </zm-form-item>
          <zm-form-item prop="minSaleNumber" class="dib">
            <zm-input class="w150" v-model="form.minSaleNumber" type="number">
              <template slot="append">张</template>
            </zm-input>
          </zm-form-item>
        </zm-form-item>
        <zm-form-item label="单张卡含券张数" prop="couponNumber">
          <zm-form-item prop="couponNumberOperationSymbol" class="dib">
            <el-select
              class="w100"
              v-model="form.couponNumberOperationSymbol"
              placeholder="请选择"
            >
              <el-option label="大于" value="1"></el-option>
              <el-option label="大于等于" value="2"></el-option>
            </el-select>
          </zm-form-item>
          <zm-form-item prop="couponNumber" class="dib">
            <zm-input class="w150" v-model="form.couponNumber" type="number">
              <template slot="append">张</template>
            </zm-input>
          </zm-form-item>
        </zm-form-item>
    </zm-form>
      <div slot="footer" class="tr">
        <el-button @click="dialogClose" type="info">取消</el-button>
        <el-button @click="onSave" type="primary">保存</el-button>
      </div>
    </zm-dialog>
  </div>
</template>
<script>
import dialogMixin from '@/mixins/dialogMixin'
export default {
  name: 'SetAll',
  components: {},
  mixins: [dialogMixin],
  props: {
    index: {
      type: [String, Number],
      default: 0
    },
    backFillData: {
      // 回填数据
      type: Object,
      default () {
        return {}
      }
    }
  },
  data () {
    return {
      form: {
        minSaleNumber: '',
        minSaleNumberOperationSymbol: '',
        couponNumber: '',
        couponNumberOperationSymbol: ''
      },
      rules: {
        minSaleNumber: {
          validator: (rule, val, callBack) => {
            if (val) {
              if (!(/^[1-9]{1,}[\d]*$/.test(val))) {
                callBack(new Error('请输入正整数!'))
              } else {
                callBack()
              }
            } else {
              callBack(new Error('请填写数值'))
            }
          }
        },
        minSaleNumberOperationSymbol: {
          required: true,
          message: '*为必填项',
          trigger: 'change'
        },
        couponNumber: {
          validator: (rule, val, callBack) => {
            if (val) {
              if (!(/^[1-9]{1,}[\d]*$/.test(val))) {
                callBack(new Error('请输入正整数!'))
              } else {
                callBack()
              }
            } else {
              callBack(new Error('请填写数值'))
            }
          }
        },
        couponNumberOperationSymbol: {
          required: true,
          message: '*为必填项',
          trigger: 'change'
        }
      }
    }
  },
  computed: {},
  watch: {},
  created () {
    this.init()
  },
  methods: {
    init () {
      if (this.backFillData && this.backFillData.minSaleNumber) {
        this.form = this.backFillData
      }
    },
    onSave () {
      this.$emit('handle-after', this.form)
      this.dialogClose()
    }
  }
}
</script>
<style scoped lang='scss'>
</style>
